package org.dingfugui.triple.protocol.mssage;

import org.dingfugui.triple.rpc.RequestMessage;
import org.dingfugui.triple.rpc.ResponseMessage;
import org.dingfugui.triple.serialize.Serialize;
import org.dingfugui.triple.serialize.jdk.JdkSerialize;

/**
 * Created by fugui.ding on 2015/4/28.
 */
public class DefaultTranslator extends AbstractDefaultTranslator {

    private Serialize serialize;

    public DefaultTranslator() {
        this.serialize = new JdkSerialize();
    }

    public DefaultTranslator(Serialize serialize) {
        this.serialize = serialize;
    }

    @Override
    public byte[] buildMessageBody(RequestMessage request) {
        return serialize.serialize(request);
    }

    @Override
    public byte[] buildMessageBody(ResponseMessage response) {
        return serialize.serialize(response);
    }

    @Override
    public RequestMessage buildRequest(byte[] body) {
        return (RequestMessage) serialize.deserialize(body);
    }

    @Override
    public ResponseMessage buildResponse(byte[] body) {
        return (ResponseMessage) serialize.deserialize(body);
    }

}
